import pandas as pd
import numpy as np
from typing import Tuple, Optional
from ..config import Config

class DataLoader:
    def __init__(self, config: Config):
        self.config = config
        
    def load_csv_data(self, file_path: str) -> pd.DataFrame:
        """Load data from CSV file
        
        Args:
            file_path (str): Path to the CSV file
            
        Returns:
            pd.DataFrame: Loaded data
        """
        try:
            df = pd.read_csv(file_path)
            return df
        except Exception as e:
            raise Exception(f"Error loading CSV file: {str(e)}")
    
    def load_time_series(self, start_date: str, end_date: str) -> pd.DataFrame:
        """Load time series data between specified dates
        
        Args:
            start_date (str): Start date in YYYY-MM-DD format
            end_date (str): End date in YYYY-MM-DD format
            
        Returns:
            pd.DataFrame: Time series data
        """
        try:
            # Implement your time series data loading logic here
            pass
        except Exception as e:
            raise Exception(f"Error loading time series data: {str(e)}")
    
    def split_data(self, data: pd.DataFrame) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
        """Split data into train, validation and test sets
        
        Args:
            data (pd.DataFrame): Input data
            
        Returns:
            Tuple[np.ndarray, np.ndarray, np.ndarray]: Train, validation and test sets
        """
        n = len(data)
        train_size = int(n * self.config.data_config['train_split'])
        val_size = int(n * self.config.data_config['val_split'])
        
        train = data[:train_size]
        val = data[train_size:train_size + val_size]
        test = data[train_size + val_size:]
        
        return train, val, test
    
    def create_sequences(self, data: np.ndarray, 
                        seq_length: Optional[int] = None) -> Tuple[np.ndarray, np.ndarray]:
        """Create sequences for time series prediction
        
        Args:
            data (np.ndarray): Input data
            seq_length (Optional[int]): Sequence length
            
        Returns:
            Tuple[np.ndarray, np.ndarray]: X (sequences) and y (targets)
        """
        if seq_length is None:
            seq_length = self.config.data_config['sequence_length']
            
        X, y = [], []
        for i in range(len(data) - seq_length):
            X.append(data[i:(i + seq_length)])
            y.append(data[i + seq_length])
            
        return np.array(X), np.array(y)